package com.eop.managedBean;

import java.io.Serializable;
import java.util.Date;

import javax.faces.model.SelectItem;

import org.operamasks.faces.annotation.Accessible;
import org.operamasks.faces.annotation.Bind;
import org.operamasks.faces.annotation.SaveState;
import org.operamasks.faces.annotation.SelectItems;

import com.base.common.provider.CommonKeySelectItemProvider;
import com.base.commons.SpringBeanHolder;
import com.base.security.SecurityReplace;
import com.base.security.SecurityUserHolder;
import com.eop.entity.Schnario;
import com.eop.service.ISchnarioService;

public class BaseSchnarioBean implements Serializable {
	protected ISchnarioService schnarioService = SpringBeanHolder
			.getBean("schnarioService");
	@Bind
	@Accessible
	@SaveState
	protected String id;
	protected Schnario sr;
	// 编号
	@Bind(id = "srCode", attribute = "value")
	protected String srCode;
	// 名称
	@Bind(id = "srName", attribute = "value")
	protected String srName;
	// 类型

	@Accessible
	protected SelectItem[] srType_items = CommonKeySelectItemProvider
			.getCommonKey("schnarioType", false);
	@Bind(id = "srType")
	@SelectItems(source = "#{this.srType_items}")
	protected String srType;
	// 适用范围大类
	@Accessible
	protected SelectItem[] srRangeBigType_items = CommonKeySelectItemProvider
			.getTopCommonKey("srRangeBigType", false);
	@Bind(id = "srRangeBigType")
	@SelectItems(source = "#{this.srRangeBigType_items}")
	protected String srRangeBigType;
	// 适用范围细类
	@Accessible
	protected SelectItem[] srRangeThinType_items = {};
	@Bind(id = "srRangeThinType")
	@SelectItems(source = "#{this.srRangeThinType_items}")
	protected String srRangeThinType;

	// 关键字
	@Bind(id = "srKeyWord", attribute = "value")
	protected String srKeyWord;
	@Bind(id = "version", attribute = "value")
	protected String version;

	// 创建者
	@Bind(id = "createUser", attribute = "value")
	protected String createUser = SecurityUserHolder.getCurrentUserId();
	@Bind(id = "createUserName", attribute = "value")
	protected String createUserName = SecurityUserHolder
			.getCurrentUserFullName();
	// 创建时间
	@Bind(id = "createDate", attribute = "value")
	protected Date createDate = new Date();

	// 版本号
	@SaveState
	@Bind(id = "srVersion", attribute = "value")
	protected String srVersion;

	// 发布单位
	@Bind(id = "publishDep", attribute = "value")
	protected String publishDep;

	// 发布时间
	@Bind(id = "publishDate", attribute = "value")
	protected Date publishDate;
	// 摘要
	@Bind(id = "model", attribute = "value")
	protected String model;
	// 备注
	@Bind(id = "remark", attribute = "value")
	protected String remark;

	protected void setSchnarioProperty() {
		if (sr == null)
			return;
		sr.setId(id);
		sr.setSrCode(srCode);
		sr.setSrName(srName);
		sr.setModel(model);
		// 新增时未发布
		sr.setPublishState(false);
		// sr.setPublishDate(publishDate);
		// sr.setPublishDep(publishDep);
		sr.setRemark(remark);
		sr.setSrKeyWord(srKeyWord);
		sr.setSrRangeBigType(srRangeBigType);
		sr.setSrRangeThinType(srRangeThinType);
		sr.setSrType(srType);
		sr.setEffect(true);
		// 版本自动生成
		// sr.setSrVersion(srVersion);

		sr.setCreateUser(createUser);
		sr.setCreateDate(new Date());
		sr.setDelFlag(false);

		sr.setVersion(version);
	}

	protected void getSchnarioProperty(Schnario sr) {
		id = sr.getId();
		srCode = sr.getSrCode();
		srName = sr.getSrName();
		model = sr.getModel();
		publishDate = sr.getPublishDate();
		publishDep = sr.getPublishDep();
		remark = sr.getRemark();
		srKeyWord = sr.getSrKeyWord();
		srRangeBigType = sr.getSrRangeBigType();
		srRangeThinType = sr.getSrRangeThinType();
		srType = sr.getSrType();
		srVersion = sr.getSrVersion();
		createUser = sr.getCreateUser();
		createUserName = SecurityReplace.replaceUserFullName(createUser);
		createDate = sr.getCreateDate();
		version = sr.getVersion();

	}

	/**
	 * 中文 是否 转换为boolean值
	 * 
	 * @param booleanStr
	 * @return
	 */
	protected boolean getBooleanValue(String booleanStr) {
		if ("是".equals(booleanStr)) {
			return true;
		} else if ("否".equals(booleanStr)) {
			return false;
		}
		return false;
	}
}
